package cn.ljy.authority.web.controller.backstage.authority;


import cn.ljy.authority.model.SysPermission;
import cn.ljy.authority.model.query.SysPermisssionQuery;
import cn.ljy.authority.service.SysPermissionService;
import cn.ljy.authority.web.controller.backstage.BaseBackstageController;
import cn.ljy.common.model.result.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "后台权限管理模块")
@RestController
@RequestMapping(value = "/backstage/authority/permission")
public class SysPermissionController  extends BaseBackstageController<SysPermission, SysPermisssionQuery,Long> {

    @Autowired
    private SysPermissionService baseService;

    @Override
    public String getAuthorityPrefix() {
        return "sys:permission"; // 定义模块权限前缀
    }

//    @ApiOperation(value = "所有权限列表")
//    @PreAuthorize("hasAuthority('sys:permission:query')")
//    @GetMapping("/all")
//    @Override
//    public ResponseData query(SysPermisssionQuery sysPermisssionQuery){
//        return super.query(sysPermisssionQuery);
//    }
//
//    @ApiOperation(value = "添加权限")
//    @PreAuthorize("hasAuthority('sys:permission:add')")
//    @Override
//    protected ResponseData add(@Validated({AddWorkValidation.class}) @RequestBody SysPermission sysPermission) {
//        return super.add(sysPermission);
//    }
//
//
//    @ApiOperation(value = "读取指定权限信息")
//    @PreAuthorize("hasAuthority('sys:permission:query')")
//    @Override
//    protected ResponseData get(@PathVariable Long id) {
//        return super.get(id);
//    }
//
//    @ApiOperation(value = "编辑权限")
//    @PreAuthorize("hasAuthority('sys:permission:edit')")
//    @Override
//    protected ResponseData edit(@Validated({UpdateWorkValidation.class}) @RequestBody SysPermission sysPermission) {
//        return super.edit(sysPermission);
//    }
//
//    @ApiOperation(value = "批量删除权限")
//    @PreAuthorize("hasAuthority('sys:permission:del')")
//    @Override
//    protected ResponseData deletes(Long[] ids) {
//       return super.deletes(ids);
//    }
//
//    @ApiOperation(value = "强制批量删除指定的多个权限")
//    @PreAuthorize("hasAuthority('sys:permission:del:force')")
//    @Override
//    protected ResponseData forceDeletes(@NotEmpty(message = "请选择要移除的记录") Long[] ids) {
//        return super.forceDeletes(ids);
//    }

    //=========================扩展部分=============================================//

    @ApiOperation(value = "所有树形权限列表")
    @GetMapping("/tree")
    @PreAuthorize("hasAuthority('sys:permission:query')")
    public ResponseData tree(SysPermisssionQuery sysPermisssionQuery){
        List<SysPermission> sysPermissions = baseService.findTree(sysPermisssionQuery);
        return ResponseData.success(sysPermissions);
    }
}
